package edu.nf.project.mappers.storeOperation.convention;

import java.util.List;
import java.util.Map;

/**
 * @Author gjh
 * @Date 2025/6/18
 * @Description: 服务定时任务的SQL语句提供类
 */
public class DishSqlProvider {
    public String updatePriorityBatchSql(Map<String, Object> params) {
        List<Integer> ids = (List<Integer>) params.get("ids");
        Integer priority = (Integer) params.get("priority");

        StringBuilder sql = new StringBuilder("UPDATE dish SET priority = ")
                .append(priority)
                .append(" WHERE dish_id IN (");

        for (int i = 0; i < ids.size(); i++) {
            sql.append("#{ids[").append(i).append("]}");
            if (i < ids.size() - 1) {
                sql.append(",");
            }
        }
        sql.append(")");
        return sql.toString();
    }

    public String resetOldTopPrioritySql(Map<String, Object> params) {
        List<Integer> ids = (List<Integer>) params.get("excludeIds");

        StringBuilder sql = new StringBuilder("UPDATE dish SET priority = 3 WHERE priority = 1");

        if (ids != null && !ids.isEmpty()) {
            sql.append(" AND dish_id NOT IN (");
            for (int i = 0; i < ids.size(); i++) {
                sql.append("#{excludeIds[").append(i).append("]}");
                if (i < ids.size() - 1) {
                    sql.append(",");
                }
            }
            sql.append(")");
        }

        return sql.toString();
    }
}
